import store from "@/store"
import { defineStore } from "pinia"
import { uploadFileApi } from "@/api/files"

export const useFilesStore = defineStore("files", () => {
  const uploadFile = (uploadData: FormData) => {
    return new Promise((resolve, reject) => {
      uploadFileApi(uploadData)
        .then((res) => {
          resolve(res)
        })
        .catch((error) => {
          reject(error)
        })
    })
  }
  return { uploadFile }
})

/** 在 setup 外使用 */
export function useFilesStoreHook() {
  return useFilesStore(store)
}
